#!/usr/bin/python

'''to monitor the system infomation '''

import psutil

def cpu_info():
    '''to monitor the cpu infomation '''
    a = psutil.cpu_count()
    print("the num of the cpu:%d" % a)
    b = psutil.cpu_times()
    print("-----the cpu all info-----")
    print(b)

def disk_info():
    '''to monitor the disk infomation '''
    disk_total = int(psutil.disk_usage('/').total/1024/1024)
    disk_used = int(psutil.disk_usage('/').used/1024/1024)
    disk_free = int(psutil.disk_usage('/').free/1024/1024)
    disk_use_percent = psutil.disk_usage('/').percent
    print("disk total: %d M"%disk_total)
    print("disk used: %d M"%disk_used)
    print("disk free: %d M"%disk_free)
    print("disk use percent: {0}%".format(disk_use_percent))

def mem_info():
    '''to monitor the memory infomation '''
    pv = psutil.virtual_memory()
    mem_total = int(pv.total/1024/1024)
    mem_used = int(pv.used/1024/1024)
    mem_free = int(pv.free/1024/1024)
    mem_use_percent = pv.percent
    print("mem total: %d M"%mem_total)
    print("mem used: %d M"%mem_used)
    print("mem free: %d M"%mem_free)
    print("mem use percent: {0}%".format(mem_use_percent))

def net_info():
    '''to monitor the net infomation '''
    pn = psutil.net_io_counters()
    net_sent = int(pn.bytes_sent/1024/1024)
    net_recv = int(pn.bytes_recv/1024/1024)
    print("net sent: %d M"%net_sent)
    print("net recv: %d M"%net_recv)

def main():
    while 1:
        print("++++++++++++++++++++++")
        print("1.look cpu info")
        print("2.look disk info")
        print("3.look mem info")
        print("4.look net info")
        print("5.exit")
        option = input("please input your choice:")
        if option == '1':
            cpu_info()
            continue
        if option == '2':
            disk_info()
            continue
        if option == '3':
            mem_info()
            continue
        if option == '4':
            net_info()
            continue
        if option == '5':
            exit()
        else:
            print("please input 1-5")

main()
